class Solution(object):
    def kWeakestRows(self, mat, k):
        m = len(mat)
        n = len(mat[0])
        p = [0] * m
        c = 0
        out = []
        for j in range(n):
            for i in range(m):
                if not mat[i][j] and not p[i]:
                    p[i] = 1
                    c += 1
                    out.append(i)
                    if c == k:
                        return out
        for i in range(m):
            if not p[i]:
                c += 1
                out.append(i)
                if c == k:
                    return out


